package com.alameda.controller.v1.menu;

import com.alameda.common.result.Result;
import com.alameda.menu.dto.AdMenuDTO;
import com.alameda.pojo.menu.AdMenuDO;
import com.alameda.service.menu.AdMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 菜单 前端控制层
 *
 * @author Lv
 * @date 2024/06/23
 */
@Api(tags = "菜单")
@RestController
@RequestMapping("/ad_menu")
public class AdMenuController {

    @Autowired
    private AdMenuService adMenuService;

    /**
     * 读取菜单树
     *
     * @return
     */
    @ApiOperation("读取菜单树")
    @PostMapping("/load_menu")
    public Result<?> loadMenu() {
        return Result.success(adMenuService.loadMenu());
    }

    /**
     * 读取菜单信息列表
     *
     * @param adMenuDTO 菜单信息
     * @return
     */
    @ApiOperation("读取菜单信息列表")
    @PostMapping("/list_menu_info")
    public Result<?> listMenuInfo(@RequestBody AdMenuDTO adMenuDTO) {
        return Result.success(adMenuService.listMenuInfo(adMenuDTO));
    }

    /**
     * 添加或修改菜单
     *
     * @param adMenuDO 菜单实体类
     * @return
     */
    @ApiOperation("添加或修改菜单")
    @PostMapping("/save_or_update")
    public Result<?> saveOrUpdate(@RequestBody AdMenuDO adMenuDO) {
        return Result.success(adMenuService.insertOrUpdate(adMenuDO));
    }

    /**
     * 删除菜单
     *
     * @param idList 菜单id集合
     * @return
     */
    @ApiOperation("删除菜单")
    @PostMapping("/remove")
    public Result<?> removeByIdList(@RequestBody List<Long> idList) {
        return Result.success(adMenuService.removeByIdList(idList));
    }

    /**
     * 导出excel
     *
     * @param adMenuDTO 菜单信息
     */
    @ApiOperation("导出excel")
    @PostMapping("/export")
    public void export(@RequestBody AdMenuDTO adMenuDTO) {
        adMenuService.export(adMenuDTO);
    }

    /**
     * 导出菜单json
     */
    @ApiOperation("导出菜单json")
    @PostMapping("/export_menu")
    public void exportMenu() {
        adMenuService.exportMenu();
    }
}

